• File: marker_generator.php
  • Full Path: C:/htdocs/reeft_gps-20250621173158/include/marker_generator.php
  • Date Modified: 11/08/2024 11:06 AM
  • File size: 3.09 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
header("Content-type: image/png");

//	Get input
if(isset($_REQUEST["text"])){
	$text = $_REQUEST["text"];
}
if(isset($_REQUEST["type"])){
	$type = $_REQUEST["type"];
}
if(isset($_REQUEST["bearing"])){
	$bearing = $_REQUEST["bearing"];
} else {
	$bearing = "";
}

//	From 1-5
//$fontSize 		= 5;

//	Marker width and height. Width is determined by text length
//$markerWidth	= strlen($text) * imagefontwidth($fontSize) + 30;
$markerHeight	= 39;

// Retrieve bounding box:
$font_size = 10; // Font size is in pixels.
$font_file = realpath('../css/fonts/verdanab.ttf'); // This is the path to your font file.

$type_space = imagettfbbox($font_size, 0, $font_file, $text);
$image_height = abs($type_space[5] - $type_space[1]);
$markerWidth = abs($type_space[4] - $type_space[0]) + 30;

//	Determines where arrow (bottompic) is placed on y-axis
$yForBottom		= 28;

//	Load pictures
switch($type){
	case "2":	//	Stamp last 15 min
		$topPic		= imagecreatefrompng("../images/marker/online-top.png");
		$bottomPic	= imagecreatefrompng("../images/marker/online-arrow.png");
		break;
	case "0":	//	> 60 min
		$topPic		= imagecreatefrompng("../images/marker/offline-top.png");
		$bottomPic	= imagecreatefrompng("../images/marker/offline-arrow.png");
		break;
    case "1":   //  15-60 min
        $topPic     = imagecreatefrompng("../images/marker/yellow-top.png");
        $bottomPic  = imagecreatefrompng("../images/marker/yellow-arrow.png");
        break;
	default:
		$topPic		= imagecreatefrompng("../images/marker/offline-top.png");
		$bottomPic	= imagecreatefrompng("../images/marker/offline-arrow.png");
}
$employeeIcon	= imagecreatefrompng("../images/marker/marker_truck_icon.png");

if($bearing != "" && $type == "2") {
	$arrowIcon	= imagecreatefrompng("../images/marker/marker_arrow_".$bearing.".png");
	$startPos = $markerWidth;
	$markerWidth = $markerWidth + 20;
}
$markerCanvas	= imagecreatetruecolor($markerWidth, $markerHeight);

//	Set blend mode
imagealphablending($markerCanvas, false);
imagesavealpha($markerCanvas, true);

//	Adjust top width and merge images
imagecopyresampled($markerCanvas, $topPic, 0, 0, 0, 0, $markerWidth, $markerHeight, imagesx($topPic), $markerHeight);	// Width is adjusted
imagecopy($markerCanvas, $bottomPic, ceil($markerWidth / 2) - ceil(imagesx($bottomPic) / 2), $yForBottom, 0, 0, 12, 11);
imagealphablending($markerCanvas, true);	//	Stop transperence before inserting icon with transperency
imagecopy($markerCanvas, $employeeIcon, 5, 6, 0, 0, 17, 13);  //truck is 17x13

if($bearing != "" && $type == "2")  {
	imagecopy($markerCanvas, $arrowIcon, $startPos, 6, 0, 0, 13, 13);  //arrow is 13x13
}

//	Text for marker
$textColor = imagecolorallocate($markerCanvas, 255, 255, 255);
//imagestring($markerCanvas, $fontSize, 25, 5, $text, $textColor);
//ImageTTFText(image, size, angle, x, y, color, font, text);
imagettftext($markerCanvas, $font_size, 0, 25, 17, $textColor , $font_file, $text);

//	Output image and destroy
imagepng($markerCanvas);
imagedestroy($markerCanvas);
imagedestroy($topPic);
imagedestroy($bottomPic);

?>